home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 9 / Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO / 042a / swagdef.zip / FILES.SWG < prev    next >
Text File  |  1993-05-28  |  16KB  |  1 lines

  1. SWAGOLX.EXE (c) 1993 GDSOFT  ALL RIGHTS RESERVED 00013         FILE HANDLING ROUTINES                                            1      05-28-9313:46ALL                      SWAG SUPPORT TEAM        FILATTR1.PAS             IMPORT              11          {> How does one go about changing a File attributeπ> from hidden to unhidden using SetFAttr ?ππTry these two Procedures on For size:π}πGetFAttr(FName:String;Var RdOnly,Hid,Sys,Arch:Boolean);πVar R:Registers;πbeginπ  FillChar(R,Sizeof(R),0);π  FName := FName+#0; { set up as a null-terminated String For Dos }π  With R Do beginπ    AH := $43;π    DS := Seg(FName); DX := ofs(FName)+1; { skip pascal length Byte }π    MsDos(R);π    RdOnly := (CL and $01) > 0;π    Hid := (CL and $02) > 0;π    Sys := (CL and $04) > 0;π    Arch := (CL and $20) > 0;π    end; { With }πend; { GetFAttr }ππPutFAttr(FName:String;RdOnly,Hid,Sys,Arch:Boolean);πVar R:Registers;πbeginπ  FillChar(R,Sizeof(R),0);π  FName := FName+#0; { set up as a null-terminated String For Dos }π  With R Do beginπ    AH := $43; AL := 1;π    DS := Seg(FName); DX := ofs(FName)+1; { skip pascal length Byte }π    if RdOnly then CL := CL or $01;π    if Hid then CL := CL or $02;π    if Sys then CL := CL or $04;π    if Arch then CL := CL or $20;π    MsDos(R);π    end; { With }πend; { PutFAttr }ππ{The File FName does not have to be opened For this to work.  In fact, itπwould probably be better if it were not.π}π                                                                                                               2      05-28-9313:46ALL                      SWAG SUPPORT TEAM        FILATTR2.PAS             IMPORT              6           {πJOE DICKSONππ> I was wondering if someone could tell me how to change the Time and Dateπ> and maybe the Attribute of a File? Lets say I want to Change:π> FileNAME.EXT 1024 01-24-93 12:33p A  to:π> FileNAME.EXT 1024 01-01-93 01:00a ARπ}ππProgram change_sample_Files_attribs;ππUsesπ  Dos;ππVarπ  f    : File;π  attr : Word;π  time : LongInt;π  DT   : datetime;ππbeginπ  assign(f, 'FileNAME.EXT');π  DT.year  := 93;π  DT.month := 1;π  DT.day   := 1;π  dt.hour  := 1;π  dt.min   := 0;π  dt.sec   := 0;π  packtime(dt, time);π  attr     := ReadOnly;π  setftime(f, time);π  setfattr(f, attr);πend.π                                               3      05-28-9313:46ALL                      SWAG SUPPORT TEAM        FILEMODE.PAS             IMPORT              16          RB > I use a shared File to transfer info betweenπ   > multitasker Windows that are running the same application.π   > Lately, I have been getting Runtime errors 2, 5 & 162 in the following spoππTry to set the "FileMode" Constant to 66 (read/Write) orπ64 (read) beFore opening it.  Here's a map of valid valuesπto FileMode:ππ                               ----- Sharing Method -----πAccess         Compatibility   Deny   Deny    Deny   DenyπMethod            Mode         Both   Write   Read   Noneπ___------------------------------------------------------πRead Only           0           16     32      48     64πWrite Only          1           17     33      49     65πRead/Write          2*          18     34      50     66ππ * = defaultππFile locking is seldom useful For Real life applications.πSometimes however, File locking MAY be appropriate, such asπwhen a Compiled list is produced at the Printer; if usersπare allowed to update the database then, the list can containπmultiple instances of a Record or reference...  :-)ππUse Record locking instead, when required, For most purposesπand add logic to prevent disasters and user misunderstandings.πUsers will generally be more happy if they're not deniedπWrite access all the time...  :-)ππRB > Perhaps I need to disable I/O checking and put in some Delays ifπ   > this File is being accessed simulataneously.  Also, the size of this FileππDefinately disable I/O checking.  Don't add Delays if youπcan avoid it.  Beware of dead-lock situations which occurπwhen two or more users access the same File With inadequateπaccess rights and they're all put on hold Until the Fileπis released by the other...  One way to catch these situationsπis to retry a specified number of times and then cancel theπoperation With an error message perhaps.π                                                                                                                           4      05-28-9313:46ALL                      SWAG SUPPORT TEAM        FILENAME.PAS             IMPORT              4           if you want to remove the period, and all Characters after it inπa valid Dos Filename, do the following...ππFileName := 'MYFile.TXT';πName := Copy(FileName, 1, Pos('.', FileName) - 1);ππThat will do it.  or you can use FSplit to break out all theπdifferent parts of a Filename/path and get it that way.ππ                                                                                5      05-28-9313:46ALL                      SWAG SUPPORT TEAM        FILESTMP.PAS             IMPORT              10          { Example For GetFTime, PackTime,π  SetFTime, and UnpackTime }ππUses Dos;πVarπ  f: Text;π  h, m, s, hund : Word; { For GetTime}π  ftime : LongInt; { For Get/SetFTime}π  dt : DateTime; { For Pack/UnpackTime}πFunction LeadingZero(w : Word) : String;πVarπ  s : String;πbeginπ  Str(w:0,s);π  if Length(s) = 1 thenπ    s := '0' + s;π  LeadingZero := s;πend;πbeginπ  Assign(f, 'RECURSEP.PAS');π  GetTime(h,m,s,hund);π  ReWrite(f); { Create new File }π  GetFTime(f,ftime); { Get creation time }π  WriteLn('File created at ',LeadingZero(h),π          ':',LeadingZero(m),':',π          LeadingZero(s));π  UnpackTime(ftime,dt);π  With dt doπ    beginπ      WriteLn('File timestamp is ',π              LeadingZero(hour),':',π              LeadingZero(min),':',π              LeadingZero(sec));π      hour := 0;π      min := 1;π      sec := 0;π      PackTime(dt,ftime);π      WriteLn('Setting File timestamp ',π              'to one minute after midnight');π      Reset(f); { Reopen File For reading }π      { (otherwise, close will update time) }π      SetFTime(f,ftime);π    end;π  Close(f);   { Close File }πend.π                                                6      05-28-9313:46ALL                      SWAG SUPPORT TEAM        FILESTR.PAS              IMPORT              10          {$B-,D-,F-,I-,L-,N-,O-,R-,S-,V-}ππUnit Filestr;ππInterfaceππUses Dos;ππFunction GetFstr(Var f: Text): String;πProcedure OpenFStr(Var f: Text);ππImplementationππVarπ  FStrBuff     : String;ππFunction GetFStr(Var f: Text): String;π  beginπ    GetFStr     := FStrBuff;π    FStrBuff[0] := #0;π    TextRec(f).BufPos := 0;π  end; { GetFStr }π  π{$F+}πFunction FStrOpen(Var f: TextRec):Word;π  { This does nothing except return zero to indicate success }π  beginπ    FStrOpen := 0;π  end; { FStrOpen }π  πFunction FStrInOut(Var f: TextRec):Word;π  beginπ    FStrBuff[0] := chr(F.BufPos);  π    FStrInOut   := 0;π  end; { FStrInOut }  π{$F-}ππProcedure OpenFStr(Var f: Text);π  beginπ    With TextRec(f) do beginπ      mode      := fmClosed;π      BufSize   := Sizeof(buffer);π      OpenFunc  := @FStrOpen;π      InOutFunc := @FStrInOut;π      FlushFunc := @FStrInOut;π      CloseFunc := @FStrOpen;π      BufPos    := 0;π      Bufend    := 0;π      BufPtr    := @FStrBuff[1];π      Name[0]   := #0;π    end; { With }π    FStrBuff[0] := #0;π    reWrite(f);π  end;  { AssignFStr }   πππend.  π                                                                     7      05-28-9313:46ALL                      SWAG SUPPORT TEAM        FILEXIST.PAS             IMPORT              6           { 1 }ππFunction FileExist(FileName : String) : Boolean;πbeginπ  FileExist := (FSearch(FileName, '') <> '')πend;      (* FileExist.                                           *)ππ{ 2 }ππFunction FileExist(FileName : String) : Boolean;πVarπ  SRec : SearchRec;πbeginπ  FindFirst(FileName, AnyFile, SRec);π  FileExist := (DosError = 0);πend;ππ{ 3 }ππFunction FileExists(FileName : String) : Boolean;πVarπ  DirInfo : SearchRec;πbeginπ  FindFirst(FileName, AnyFile, DirInfo);π  if (DosError = 0) thenπ    FileExists := Trueπ  elseπ    FileExists := False;πend;ππ                                                                                     8      05-28-9313:46ALL                      SWAG SUPPORT TEAM        FILSHAR1.PAS             IMPORT              6           Program ShareVolation;πUses Dos,Crt;πVarπ  Dummy:    Boolean;ππFunction FileOpen(F:String):Boolean;πVarπ  Regs: Registers;π  I:    Byte;πbeginπ  With Regs doπ  beginπ    Ah := $3d;π    Al := 2;π    Ds := Seg(F);π    Dx := Ofs(F)+1;π  end;π  Intr($21,Regs);ππ  WriteLn(F,' open: ',Regs.Ax = 5);π  FileOpen := (Regs.Ax = 5);πend; { FileOpen }ππbeginπ  Dummy := FileOpen('D:\FILSHARE.EXE'+#0);π  Dummy := FileOpen('C:\CONFIG.SYS'+#0);π  Dummy := FileOpen('C:\IO.SYS'+#0);π  Dummy := FileOpen('C:\MSDos.SYS'+#0);πend.ππ{πAnd the funny thing was that it worked..π(But it returns error code 6 [Invalide handle] on closed Files)..π}               9      05-28-9313:46ALL                      SWAG SUPPORT TEAM        FILSHAR2.PAS             IMPORT              7           Program ShareVolation;πUses Dos,Crt;ππFunction FileOpen(S:String):Boolean; Assembler;π{ -returns True if File already is open (Access denied) ..}πAsmπ  PUSH DS             { changes are in all caps }π  mov  ah,03dhπ  xor  al,alπ  LDS  DX, Sπ  INC  DX          { point to contents of String }π  int  21hπ  mov  bx,axπ  mov  al,0  { FileOpen = False }π  jnc  @endπ  cmp  bx,05h  { Access denied}π  jz   @Openπ  jmp  @endππ@Open:π  mov al,1  { FileOpen = True}π@end:π   POP DSπend; { FileOpen }πππVarπ   F : Text ;ππbeginπ   FileMode := $10 ;                 { deny read/Write ?? }π   Assign( F, 'C:\TEST.TXT' ) ;π   ReWrite( F ) ;ππ   WriteLn(FileOpen('C:\TEST.TXT'+ #0));  { SHARE is loaded }π   Close( F ) ;πend.π                                                       10     05-28-9313:46ALL                      SWAG SUPPORT TEAM        FILSHAR3.PAS             IMPORT              18          FileSHARinG !πππWhen sharing Files concurrently, by means of For example a multitasker or aπnetwork, it is necessary to use the File sharing as provided by the Dosπcommand SHARE, or as provided by a Network shell (In Novell File sharing isπsupported by the network shell on Servers, not locally. Check your networkπdocumentation For more inFormation).ππFile sharing is simple in TP/BP, since the system Variable FileMode definesπin what mode a certain File is opened in:ππConstπ   fmReadOnly  = $00;  (* *)π   fmWriteOnly = $01;  (* Only one of these should be used *)π   fmReadWrite = $02;  (* *)ππ   fmDenyAll   = $10;  (* together With only one of these  *)π   fmDenyWrite = $20;  (* *)π   fmDenyRead  = $30;  (* *)π   fmDenyNone  = $40;  (* *)ππ   fmNoInherit = $70;  (* Set For "No inheritance"         *)πππConstruction the FileMode Variable is easy, just add the appropriate values:ππFileMode:=fmReadOnly+fmDenyNone;π      (Open File For reading only, allow read and Write.)ππFileMode:=fmReadWrite+fmDenyWrite;π      (Open File For both read and Write, deny Write.)ππFileMode:=fmReadWrite+fmDenyAll;π      (Open File For both read and Write, deny all.)ππSay you open the File in "fmReadWrite+fmDenyWrite". This will let you readπand Write freely in the File, While other processes can freely read the File.πif another process tries to open the File For writing, that process will getπthe error "Access denied".ππ(fmNoInherit is seldom used - it defines if a childprocess spawn from yourπprocess will be able to use the Filehandle provided by your process.)ππThe FileMode Variable is only used when the File is opened;ππ ...πAssign(F,FileName);πFileMode:=fmReadOnly+fmDenyNone;πReset(F);πFileMode:=<Whatever>    (* Changing FileMode here does not affect theπ                           Files already opened *)ππBy default, FileMode is defined as FileMode:=$02 in TP/BP, this is referredπto as "Compatibility mode" in the TP/BP docs. Two processes accessing theπsame File With this Filemode results in the critical error "Sharingπviolation".π----------------------------------------------------------------------π                                                           11     05-28-9313:46ALL                      SWAG SUPPORT TEAM        LOCKFILE.PAS             IMPORT              12          {π> Does anyone have any multi-tasking/File sharing Units (preferablyπ> With well documented code).  Specifically, I need to Write a Programπ> that _may_ be active on one node, and I'd like to open the Files inπ> read-only Form, amung other things, so that I can load that inπ> multi-node (shared) environment.ππ}ππFunction LockFile(f : File) : Boolean;  { returns True if lock achieved. }π                                        { if not, File locked by other   }π                                        { application running.           }ππVarπ  r : Registers;   {Defined in Dos Unit}π  l : LongInt;ππbeginπ  r.ah := $5C;π  r.al := 0;π  Move(f,r.bx,2);   {Places File handle into BX register.}π  r.cx := 0;  {Most significant, region offset (0 - beginning of File)}π  r.dx := 0;  {Least significant, region offset (0 - beginning of File)}π  l := FileSize(f);         { Get File size }π  r.di := l and $ffff;      { Devide File size to most/least parts }π  r.si := l div $10000;     { For locking the entire File.         }π  MsDos(r);π  LockFile := ((r.flags and 1)=0);π  { if carry flag is set File locking failed, reason in AX }πend;ππ{πBTW: to unlock it use the same routine, but change the  r.al to 1.ππif this routine fails, it means that the File is locked in the otherπtask, and cannot be used.π}                                                                                                        12     05-28-9313:46ALL                      SWAG SUPPORT TEAM        MAXFILES.PAS             IMPORT              9           {π>I'm searching For a possibility to access more then 20 (I don't know the exactπ>number) Files at once With TP 7.0 (Real mode). I'll be happy if anyone can postπ>me sourcecode and technical information - technical information alone would beπ>enough, too.ππBoland Magazin 6/92 (Hot Line) Writes:ππThere is error in Dos: it's equal what you in Config.sys after Files= Write,πit can manage only 15 (!) open Files. Here is an Unit to outwit it:π(should be as first, can be not in overlay, entry also in config.sys)π}ππUnit maxFiles;ππInterfaceππConstπ  maxFile = 255;π  {for 250 open Files}πVarπ  index: Integer;π  puffer: Array[1..maxFile] of Byte;ππbeginπ  For index := 1 to maxFile doπ    puffer[index] := $FF;π  For index := 1 to 5 doπ    puffer[index] := mem[prefixseg:$18 + pred(index)];π  memw[prefixseg:$32] := maxFile;π  memw[prefixseg:$34] := ofs(puffer);π  memw[prefixseg:$36] := seg(puffer);πend.π                                                                                                                     13     05-28-9313:46ALL                      SWAG SUPPORT TEAM        TRUENAME.PAS             IMPORT              8           {πNORBERT IGLππ> Anyone has got an idea on how to know if a drive is a real one or theπ> result of a SUBST command Any help... welcome :-)ππWell, DOS ( esp. COMMAND.COM ) has a undocumented Commandπcalled TRUENAME, which takes wildcards also.π}ππProgram TrueName;ππusesπ  DOS;ππfunction RealName(FakeName : String) : String;πVarπ  Temp : String;π  Regs : Registers;πbeginπ  FakeName := FakeName + #0; { ASCIIZ }π  With Regs doπ  beginπ    AH := $60;π    DS := Seg(FakeName);π    SI := Ofs(FakeName[1]);π    ES := Seg(Temp);π    DI := OfS(Temp[1]);π    INTR($21, Regs);π    DOSERROR := AX * ((Flags And FCarry) shr 7);π    Temp[0] := #255;π    Temp[0] := CHAR(POS(#0, Temp) - 1);π  end;π  If DosError <> 0 thenπ    Temp := '';π  RealName := Temp;πend;ππbeginπ  writeln(RealName(Paramstr(0)));πend.π